package com.sunyur.tailor.channel.service.middle.user.impl;

import com.sunyur.tailor.channel.common.middle.base.ChannelListResult;
import com.sunyur.tailor.channel.common.middle.base.ChannelResult;
import com.sunyur.tailor.channel.common.middle.util.ChannelResultUtil;
import com.sunyur.tailor.channel.service.inner.user.param.UserSyncParam;
import com.sunyur.tailor.channel.service.inner.user.service.SunyurUserService;
import com.sunyur.tailor.channel.service.outer.user.model.OuterUserModel;
import com.sunyur.tailor.channel.service.outer.user.param.OuterUserParam;
import com.sunyur.tailor.channel.service.middle.user.MiddleUserService;
import com.sunyur.tailor.channel.service.outer.user.service.OuterUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @Author 99288
 * @Description 用户业务实现类
 * @Date 23:30 2021/7/7
 * @Param
 * @return
**/
@Slf4j
@Service("middleUserService")
public class MiddleUserServiceImpl implements MiddleUserService {

    @Autowired
    private SunyurUserService sunyurUserService;

    @Autowired
    private OuterUserService outerUserService;

    @Override
    public ChannelResult syncUser(OuterUserParam outerUserParam){
        //调用外部获取数据
        ChannelListResult<OuterUserModel> outerUserResult = outerUserService.getUserList(outerUserParam);
        if(ChannelResultUtil.isSuccess(outerUserResult)) {
            List<OuterUserModel> outerUserList = outerUserResult.getContent();
            //数据转换
            List<UserSyncParam> userSyncParamList = this.conversion(outerUserList);
            //调用内部同步数据
            sunyurUserService.syncUserList(userSyncParamList);

        }
        return ChannelResultUtil.success(Boolean.TRUE);
    }

    /**
     * 数据实体类转换
     */
    private List<UserSyncParam> conversion(List<OuterUserModel> outerUserList){
        List<UserSyncParam> userSyncParamList = new ArrayList<>();

        return userSyncParamList;
    }
}
